/**
 * Created by 张淑曼 on 2018/12/12.
 */
/*
* loadMap china.json
* 点击省下钻到市  重新loadMap 传值 山东.json
* 重新加载换数据
* */
/*
* 中间地图
*   图标 symbolType
*   图标颜色 symbolColor
*   数据
* */


var symbolType = 'circle' ;
var symbolColor = '#DCBD40';
var dataMap = [];
function chinaMap(dataMap) {
    var bdCharts = echarts.init(document.getElementById('bdCharts'));
    var mapName = 'china';

    /*
     * 下钻地图json
     * */
    var provinces = {
        '山东' : '../data/shandong.json',
        '辽宁' : '../data/liaoning.json',
        '黑龙江' : '../data/heilongjiang.json',
        '吉林' : '../data/jilin.json',
        '北京' : '../data/beijing.json',
        '天津' : '../data/tianjin.json',
        '河北' : '../data/hebei.json',
        '陕西' : '../data/shanxi1.json',
        '山西' : '../data/shanxi.json',
        '河南' : '../data/henan.json',
        '江苏' : '../data/jiangsu.json',
        '上海' : '../data/shanghai.json',
        '安徽' : '../data/anhui.json',
        '浙江' : '../data/zhejiang.json',
        '福建' : '../data/fujian.json',
        '江西' : '../data/jiangxi.json',
        '湖南' : '../data/hunan.json',
        '湖北' : '../data/hubei.json',
        '重庆' : '../data/chongqing.json',
        '四川' : '../data/sichuan.json',
        '甘肃' : '../data/gansu.json',
        '青海' : '../data/qinghai.json',
        '宁夏' : '../data/ningxia.json',
        '西藏' : '../data/xizang.json',
        '新疆' : '../data/xinjiang.json',


    };

    //高亮区域
    var lightColor = '#3B70E4';
    var light= [{
            name: '新疆',
            itemStyle: {
                areaColor: lightColor,
                color: lightColor
            }
            },{
                name: '西藏',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '青海',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '甘肃',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '宁夏',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '四川',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '重庆',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '山西',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '山西',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '湖北',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '湖南',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '河南',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '江西',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '福建',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '浙江',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '上海',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '安徽',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '江苏',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '山东',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '河北',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '北京',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '天津',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '辽宁',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '吉林',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '黑龙江',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '新疆',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '新疆',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            },{
                name: '陕西',
                itemStyle: {
                    areaColor: lightColor,
                    color: lightColor
                }
            }];
    //dataMap = [
    //    {name: "青海", value: 177},
    //    {name: "西藏", value: 42},
    //    {name: "新疆", value: 102},
    //    {name: "山西", value: 81},
    //    {name: "吉林", value: 47},
    //];

    /*
        获取地图气泡数据
    */
    var geoCoordMap = {};
    bdCharts.showLoading();
    var mapFeatures = echarts.getMap(mapName).geoJson.features;
    bdCharts.hideLoading();
    mapFeatures.forEach(function (v) {
        // 地区名称
        var name = v.properties.name;
        // 地区经纬度
        geoCoordMap[name] = v.properties.cp;

    });


    /*
    *   气泡大小
    * */
    var max = 580,
        min = 20; // todo
    var maxSize4Pin = 300,
        minSize4Pin = 110;
    var convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value),
                });
            }
        }
        return res;
        console.log(res);

    };
    console.log(convertData(dataMap));
    bdCharts.on('dblclick', function (params) {
        clearTimeout(timeFn);
        $('.map').hide();
        loadMap('../data/china.json', 'china');
        symbolType = 'circle' ;
        symbolColor = '#DCBD40';
        mapxqResult(0);
        $('.tab p').eq(0).addClass('active').siblings().removeClass('active');
        sbxsData(0);
        ztpjData(0);
        ztpjResult(0);
        sbjxResult(0);
        xqlResult(0);
    })

    //单击切换到省级地图，当mapCode有值,说明可以切换到下级地图
    var timeFn = null;
    bdCharts.on('click', function(params) {
        clearTimeout(timeFn);
        console.log(params.name);
        //由于单击事件和双击事件冲突，故单击的响应事件延迟250毫秒执行
        timeFn = setTimeout(function() {
            var name = params.name; //地区name
            var mapCode = provinces[name]; //地区的json数据
            /*
            * mapName
            * */
            var mapCodeName = mapCode.slice(8,mapCode.length);
            var i = mapCodeName.lastIndexOf('.');
            var getMapName = mapCodeName.slice(0,i);
            console.log(mapName)
            if (!mapCode) {
                //alert('无此区域地图显示');
                return;
            }else{
                $('.map').show();
            }
            dataMap = [
                //{name:'青岛市',value:60},
                //{name:'济南市',value:90},
            ];
            //symbolType='roundRect';
            //symbolColor = '#fc6752';
            var mapFeatures = echarts.getMap(getMapName).geoJson.features;
            bdCharts.hideLoading();
            mapFeatures.forEach(function (v) {
                // 地区名称
                var name = v.properties.name;
                // 地区经纬度
                geoCoordMap[name] = v.properties.cp;

            });
            //option.series[0].symbolSize=[100,50];
            loadMap(mapCode, name);
            console.log(convertData(dataMap));
        }, 250);
    });

    //初始化
    loadMap('../data/china.json', 'china');


    function loadMap(mapCode, name ) {
        $.get(mapCode, function(data) {
            if (data) {
                echarts.registerMap(name, data);
                var option = {
                    visualMap: {
                                show: false,
                                min: 0,
                                max: 200,
                                left: 'left',
                                top: 'bottom',
                                text: ['高', '低'], // 文本，默认为数值文本
                                calculable: true,
                                seriesIndex: [1],
                                inRange: {
                                    color: ['#3B76F6', '#3B76F6'] // 浅蓝
                                }
                            },
                    geo: {
                        show: true,
                        map: name,
                        label: {
                            normal: {
                                show: true,
                                textStyle: {
                                    fontSize: 32,
                                    color: '#fff'
                                }
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: 32,
                                    color: '#fff'
                                }
                            }
                        },
                        regions: light,
                        z:10,
                        roam: false,
                        itemStyle: {
                            normal: {
                                areaColor: '#2558C0',
                                borderColor: '#04C9C5',
                                shadowColor: '#000',
                                //shadowBlur: 50,
                                borderWidth:5,
                            },
                            emphasis: {
                                areaColor: '#2558C0',
                                borderColor:'#F0D340',
                                label:{
                                    normal:{
                                        show:true,
                                        textStyle:{
                                            color:'#fff'
                                        }
                                    }

                                }
                            }
                        },
                    },
                    series: [
                        {
                            name: '点',
                            type: 'scatter',
                            coordinateSystem: 'geo',
                            symbol: symbolType, //气泡 圆circle  气泡pin
                            symbolSize: function (val) {
                                var a = (maxSize4Pin - minSize4Pin) / (max - min);
                                var b = minSize4Pin - a * min;
                                b = maxSize4Pin - a * max;
                                return a * val[2] + b;
                            },
                            symbolOffset:[-50,-10],
                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        color: '#fff',
                                        fontSize: 34,
                                    },
                                    formatter: function (params) {
                                        return params.value[2]
                                    },

                                }
                            },
                            itemStyle: {
                                normal: {
                                    //color: symbolColor, //标志颜色
                                    color:function(params){
                                        //console.log(params);
                                        //if(params.data.value[2] > 100){
                                        //    return '#CA2A66'
                                        //}else{
                                            return symbolColor
                                        //}
                                    }
                                }
                            },
                            zlevel: 100,
                            data: convertData(dataMap),
                        },

                        {
                            type: 'map',
                            map: name,
                            geoIndex: 1,
                            z:-1,
                            aspectScale: 0.75, //长宽比
                            showLegendSymbol: false, // 存在legend时显示
                            label: {
                                normal: {
                                    show: true,
                                    textStyle: {
                                        fontSize: 32,
                                        color: '#fff'
                                    }
                                },
                                emphasis: {
                                    show: false,
                                }
                            },
                            roam: false,
                            itemStyle: {
                                normal: {
                                    areaColor: '#2558C0',
                                    borderColor: '#04C9C5',
                                    shadowBlur: 50,
                                    borderWidth:5,
                                },
                                emphasis: {
                                    areaColor: '#2B91B7',
                                    borderColor:'#ff0',
                                }
                            },
                        },
                        ]
                };
                bdCharts.setOption(option);
                // curMap = {
                //     mapCode: mapCode,
                //     mapName: name
                // };
            } else {
                alert('无法加载该地图');
            }
        });
    }


}
//chinaMap();

/*
* 状态评价测试
* */
//$('#state').click(function () {
//    $(this).addClass('hover').parent().siblings().children().removeClass('hover');
//    symbolType = 'pin';
//    symbolColor = '#C92965';
//    chinaMap();
//})


/*
* 设备巡视
* */
function sbxs(data){
    var sbxsfgl = echarts.init(document.getElementById('sbxsfgl'));
    sbxsfgloption = {
        title : {
            text: data+'%',
            subtext: '覆盖率',
            left: 'center',
            top: '42%',
            textStyle: {
                color:'#EDF84D',
                fontSize:50,
            },
            subtextStyle:{
                color:'#fff',
                fontSize:30
            }

        },
        series: [
            {
                name: "",
                type: "gauge",
                radius: "62%",
                startAngle: 0,
                endAngle: 359.9,
                splitNumber: 25,
                hoverAnimation: true,
                axisTick: {
                    show: false
                },
                splitLine: {
                    length: 40,
                    lineStyle: {
                        width: 15,
                        color: "#05164A"
                    }
                },
                axisLabel: {
                    show: false
                },
                pointer: {
                    show: false
                },
                axisLine: {
                    lineStyle: {
                        opacity: 0
                    }
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: ""
                }]
            },
            {
                name: "",
                type: "pie",
                radius: ["78%","80%"],
                hoverAnimation: true,
                z: 0,
                zlevel: 0,
                label: {
                    normal: {
                        show: false,
                        position: "center"
                    }
                },
                data: [{
                    value: 100,
                    name: "",
                    label: {
                        normal: {
                            show: false
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: "#0B3963"
                        }
                    }
                }
                ]
            },
            {
                name: "",
                type: "pie",
                radius: ["85%","87%"],
                hoverAnimation: true,
                z: 0,
                zlevel: 0,
                label: {
                    normal: {
                        show: false,
                        position: "center"
                    }
                },
                data: [{
                    value: 100,
                    name: "",
                    label: {
                        normal: {
                            show: false
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: "#0B3963"
                        }
                    }
                }
                ]
            },
            {
                name: "",
                type: "pie",
                radius: ["52%","62%"],
                silent: true,
                label: {
                    normal: {
                        show: true,
                        position: "center"
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                z: 0,
                zlevel: 0,
                data: [{
                    value: 5,
                    name: "",
                    label: {
                        normal: {
                            show: true
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: "#0F4971"
                        }
                    }
                },
                    {
                        value: data,
                        name: "",
                        label: {
                            normal: {
                                show: true
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: "#76E4FF"
                            }
                        }
                    }
                ]
            },
        ]
    }
    sbxsfgl.setOption(sbxsfgloption);
}

/*
* 状态评价
* */
function ztpj(data){
    var ztpjfgl = echarts.init(document.getElementById('ztpjfgl'));
    ztpjfgloption = {
        title : {
            text: '覆盖率',
            subtext: data+'%',
            left: 'center',
            top: '42%',
            textStyle: {
                color:'#fff',
                fontSize:30
            },
            subtextStyle:{
                color:'#EDF84D',
                fontSize:50,
                fontWeight:'bold'

            }
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} : ({d}%)"
        },
        series: [{
            name: "",
            center: [
                "50%",
                "50%"
            ],
            radius: [
                "64%",
                "65%"
            ],
            clockWise: false,
            hoverAnimation: false,
            type: "pie",
            data: [{
                value: 100-data,
                name: "",
                label: {
                    normal: {
                        show: false,
                    }
                },
                labelLine: {
                    show: false
                },
                itemStyle: {
                    normal: {
                        color: "#1B2789",
                        borderColor: new echarts.graphic.LinearGradient(1, 0, 0, 1, [{
                            offset: 0,
                            color: '#1B2789'
                        }, {
                            offset: 1,
                            color: '#1B2789'
                        }]),
                        borderWidth: 35
                    },
                },
            }, {
                name: " ",
                value: data,
                label: {
                    normal: {
                        show: false,
                    }
                },
                labelLine: {
                    show: false
                },
                itemStyle: {
                    normal: {
                        //color: "#1612B8",
                        borderColor: new echarts.graphic.LinearGradient(1, 1, 0, 1, [{
                            offset: 0,
                            color: '#1612B8'
                        }, {
                            offset: 1,
                            color: '#4EDBE5'
                        }]),
                        borderWidth: 35
                    },
                },
            }]

        }]
    };
    ztpjfgl.setOption(ztpjfgloption);
}

/*
* 设备检修
* */
function sbjx(data){
    var sbjx = echarts.init(document.getElementById('sbjx'));
    sbjxoption = {
        grid: {
            left: '0%',
            right: '0%',
            bottom: '5%',
            top: '9%',
            height: '85%',
            containLabel: true,
            z: 22
        },
        xAxis: [{
            type: 'category',
            gridIndex: 0,
            data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
            axisTick: {
                alignWithLabel: true
            },
            axisLine: {
                lineStyle: {
                    color: '#ABDDF5',
                    width:3
                }
            },
            axisLabel: {
                show: true,
                color: '#6E8DFD',
                fontSize:32
            }
        }],
        yAxis: [{
            type: 'value',
            gridIndex: 0,
            name:'(万次)',
            nameTextStyle:{
                //   textStyle:{
                color:'#4D69C8',
                fontSize:32,
                //   }
            },
            splitLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            min: 0,
            //max: 10,
            axisLine: {
                lineStyle: {
                    show:false,
                    color: 'transparent',

                }
            },

            axisLabel: {
                color: '#4D69C8',
                formatter: '{value}',
                textStyle:{
                    fontSize:32
                }
            }
        },
            {
                type: 'value',
                gridIndex: 0,
                min: 0,
                //max: 10,
                splitNumber:5,
                splitLine: {
                    show: false
                },
                axisLine: {
                    show: false,

                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                splitLine:{
                    lineStyle:{
                        color:'#0F2A71',
                        width:3,
                    }
                },
                splitArea: {
                    show: false,
                    areaStyle: {
                        color: ['#041543', '#041543']
                    }
                }
            }
        ],
        series: [{
            name: '合格率',
            type: 'bar',
            barWidth: '50%',
            xAxisIndex: 0,
            yAxisIndex: 0,
            itemStyle: {
                normal: {
                    color:'#0EC189'
                }
            },
            label:{
                normal:{
                    show:true,
                    position:'top',
                    textStyle:{
                        color:'#6B8AF7',
                        fontSize:24,
                    },
                    offset:[0,-10]
                }
            },
            data: data,
            zlevel: 11

        },
            {
                name: '背景',
                type: 'bar',
                barWidth: '50%',
                xAxisIndex: 0,
                yAxisIndex: 1,
                barGap: '-100%',

                data: [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],
                itemStyle: {
                    normal: {
                        color: 'rgba(14,193,137,.1)'
                    }
                },
                zlevel: 9
            },

        ]
    };


    sbjx.setOption(sbjxoption);
}


/*
* 危急 消缺率
* */
function xql(data1,data2){
    var xql = echarts.init(document.getElementById('xql'));

    xqloption =  {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                lineStyle: {
                    color: '#57617B'
                }
            }
        },
        legend: {
            icon: 'rect',
            itemWidth: 50,
            itemHeight: 15,
            itemGap: 13,
            data: ['严重', '危急'],
            right: '4%',
            textStyle: {
                fontSize: 32,
                color: '#5172D6',
            }
        },
        grid: {
            left: '0%',
            right: '2%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            boundaryGap: false,
            axisLine: {
                lineStyle: {
                    color: '#597BA3',
                    width:3
                }
            },
            axisLabel:{
                textStyle:{
                    color:'#5172D6',
                    fontSize:32
                }
            },
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
        }],
        yAxis: [{
            type: 'value',
            axisTick: {
                show: false
            },
            name:'%',
            //min:80,
            max:100,
            axisLine: {
                lineStyle: {
                    show:false,
                    color: 'transparent'
                }
            },
            nameTextStyle:{
                fontSize: 32,
                color:'#5172D6',
            },
            axisLabel: {
                margin: 10,
                textStyle: {
                    fontSize: 32,
                    color:'#5172D6',
                }
            },
            splitNumber: 5,
            splitLine: {
                lineStyle: {
                    color: '#1A3E91',
                    width:3,
                }
            }
        }],
        series: [{
            name: '危急',
            type: 'line',
            smooth: true,
            lineStyle: {
                normal: {
                    width: 4
                }
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: 'rgba(244,105,31, 0.3)'
                    }, {
                        offset: 0.8,
                        color: 'rgba(244,105,31, 0)'
                    }], false),
                    shadowColor: 'rgba(0, 0, 0, 0.1)',
                    shadowBlur: 10
                }
            },
            itemStyle: {
                normal: {
                    color: 'rgb(244,105,31)'
                }
            },
            data: data1
        }, {
            name: '严重',
            type: 'line',
            smooth: true,
            lineStyle: {
                normal: {
                    width: 4
                }
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: 'rgba(225,220,83, 0.3)'
                    }, {
                        offset: 0.8,
                        color: 'rgba(225,220,83, 0)'
                    }], false),
                    shadowColor: 'rgba(0, 0, 0, 0.1)',
                    shadowBlur: 10
                }
            },
            itemStyle: {
                normal: {
                    color: 'rgb(225,220,83)'
                }
            },
            data: data2
        }]
    };
    xql.setOption(xqloption);
}
xql()


/*
* 地图上  tab
* */
var i=0;
$('.tab p').click(function(){
    i = $(this).index();
    $(this).addClass('active').siblings().removeClass('active');
    sbxsData(i);
    ztpjData(i);
    ztpjResult(i);
    sbjxResult(i);
    xqlResult(i)
    //地图数据
    if(i==1){
        mapxqResult(1);
    }else if(i==2){
        mapxqResult(2);
    }else if(i==0){
        mapxqResult(0);
    }

})



//设备巡视
function sbxsData(i){
    $.ajax({
        type:'POST',
        url:url+'getInspectionCoverageData',
        data:null,
        dataType:'json',
        success:function(data){
            if(i==0){
                sbxs(data[0]['变电覆盖率'].replace('%',''));
            }else if(i==1){
                sbxs(data[0]['输电覆盖率'].replace('%',''));
            }else if(i==2){
                sbxs(data[0]['配网覆盖率'].replace('%',''));
            }
        },
        error:function(err){
            console.log(err);
        }
    });
}

//状态评价
function ztpjData(i){
    $.ajax({
        type:'POST',
        url:url+'getEvaluationCoverage',
        data:null,
        dataType:'json',
        success:function(data){
            if(i==0){
                ztpj(data[0]['变电覆盖率'].replace('%',''));
            }else if(i==1){
                ztpj(data[0]['输电覆盖率'].replace('%',''));
            }else if(i==2){
                ztpj(data[0]['配网覆盖率'].replace('%',''));
            }
        },
        error:function(err){
            console.log(err);
        }
    });
}

//评价结果
function ztpjResult(i){
    var ztpjName;
    if(i == 0){
        ztpjName = 'getPowerStateAppraisal';
    }else if(i == 1){
        ztpjName = 'getTransStateAppraisal';
    }else{
        ztpjName = 'getDnsStateAppraisal';
    }
    $.ajax({
        type:'POST',
        url:url+ztpjName,
        data:null,
        dataType:'json',
        success:function(data){
            var html='';
            for(var r=0;r<data.length;r++){
                html +=`
                    <tr>
                        <td>${data[r]['省公司']}</td>
                        <td>${data[r]['正常']}</td>
                        <td>${data[r]['注意']}</td>
                        <td>${data[r]['异常']}</td>
                        <td>${data[r]['严重']}</td>
                    </tr>
                `
            }
            $('#ztpjResult').html(html);
        },
        error:function(err){
            console.log(err);
        }
    });
}

//设备检修
function sbjxResult(i){
    var sbjxName;
    if(i == 0){
        sbjxName = 'getDevSubFinishRateTime';
    }else if(i == 1){
        sbjxName = 'getTranElecFinishRateTime';
    }else{
        sbjxName = 'getDmsFinishRateTime';
    }
    $.ajax({
        type:'POST',
        url:url+sbjxName,
        data:null,
        dataType:'json',
        success:function(data){
            var arr=[];
            for(var i=0;i<data.length;i++){
                if(data[i]['检修量(万次)'] !== null){
                    arr.push(fix(data[i]['检修量(万次)']));
                }
            }
            sbjx(arr);
        },
        error:function(err){
            console.log(err);
        }
    });
}

//消缺率
function xqlResult(i){
    var xqlName;
    if(i == 0){
        xqlName = 'subVacancyRateTime';
    }else if(i == 1){
        xqlName = 'tranElecVacancyRateTime';
    }else{
        xqlName = 'dmsVacancyRateTime';
    }
    $.ajax({
        type:'POST',
        url:url+xqlName,
        data:null,
        dataType:'json',
        success:function(data){
            console.log(data);
            var arr1=[],arr2=[];
            for(var i=0;i<data.length;i++){
                arr1.push(data[i]['严重']);
                arr2.push(data[i]['危及']);

            }
            xql(arr1,arr2);
        },
        error:function(err){
            console.log(err);
        }
    });
}


//地图设备检修
// 没数据
function mapjxResult(i){
    var mapjxName;
    if(i == 0){
        mapjxName = 'getDevSubFinishRateUnit';
    }else if(i == 1){
        mapjxName = 'getTranElecFinishRateUnit';
    }else{
        mapjxName = 'getDmsFinishRateUnit';
    }
    $.ajax({
        type:'POST',
        url:url+mapjxName,
        data:null,
        dataType:'json',
        success:function(data){
            console.log(data);
            var arr=[];
            for(var i=0;i<data.length;i++){
                //if(data[i]['检修量(万次)'] !== null){
                //    arr.push(fix(data[i]['检修量(万次)']));
                //}
            }
            //mapjx(arr);
        },
        error:function(err){
            console.log(err);
        }
    });
}

//地图设备检修
$('#jx').click(function(){
    mapjxResult(i);
});

//地图消缺率
function mapxqResult(i){
    var mapxqName;
    if(i == 0){
        mapxqName = 'subVacancyRateUnit';
    }else if(i == 1){
        mapxqName = 'tranElecVacancyRateUnit';
    }else{
        mapxqName = 'dmsVacancyRateUnit';
    }
    $.ajax({
        type:'POST',
        url:url+mapxqName,
        data:null,
        dataType:'json',
        success:function(data){
            console.log(data);
            var arr1=[],arr2=[],arr3=[];
            for(var i=0;i<data.length;i++){
                arr1.push(data[i]['月份']);
                arr2.push(data[i]['危及']);
                arr3.push(data[i]['严重']);
            }
            //    排序
            var sortArr = arr3.sort(command);
            function command(val1,val2){
                return val1-val2;
            }
            //取数 最小三位
            var min = sortArr.slice(0,3);
            console.log(min);
            var minArr = [];
            for(var i=0;i<data.length;i++){
                for(var j=0;j<min.length; j++){
                    if(data[i]['严重'] == min[j]){
                        minArr.push(data[i]);
                    }
                }
            }
            //取数 最大三位
            var max = sortArr.slice(-3);
            var maxArr = [];
            for(var i=0;i<data.length;i++){
                for(var j=0;j<max.length; j++){
                    if(data[i]['严重'] == max[0] && maxArr.indexOf(data[i]['严重']) == -1){
                        maxArr.push(data[i]);
                    }
                }
            }
            console.log(maxArr);
            var temp=[];
            for(var i=0;i<maxArr.length;i++){
                if(temp.indexOf(maxArr[i]) == -1 ){
                    temp.push(maxArr[i])
                }
            }

            //
            temp = temp.slice(0,3);
            for(var i=0;i<temp.length;i++){
                minArr.push(temp[i]);
            }
            var data=[];
            for(var i=0;i<minArr.length;i++){
                var obj={};
                if(minArr[i]['月份'] == '冀北'){
                    minArr[i]['月份'] = '河北'
                }
                obj.name = minArr[i]['月份'];
                obj.value = minArr[i]['严重'];
                data.push(obj);
            }

            console.log(data);
            dataMap = data;
            chinaMap(dataMap);

        },
        error:function(err){
            console.log(err);
        }
    });
}

//点击标签 地图消缺率改变
$('#xq').click(function(){
    $('.leftBox .title').removeClass('hover');
    $(this).addClass('hover').parent().siblings().children().removeClass('hover');
    //symbolType = 'pin';
    //symbolColor = '#e34904';
    mapxqResult(i);
});


$(document).ready(function () {
    sbxsData(0);
    ztpjData(0);
    ztpjResult(0);
    sbjxResult(0);
    xqlResult(0);
    //地图目前默认显示的是消缺率的数据
    mapxqResult(i);

});
/*
* 现场监控
* */
$('#video').click(function(){
    location.href = '../jygk-video/jygk-video.html';
})




